/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package introsemp;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.WindowConstants;

/**
 *
 * @author Marit
 */
public class ActivityUI {
    
    JDialog dbox = new JDialog();
    JLabel actLabel = new JLabel("Activity:");
    JLabel itemLabel = new JLabel("Items:");
    JComboBox actList = new JComboBox();
    JTextField itemField = new JTextField();
    JButton ok = new JButton("OK");
    JButton cancel = new JButton("Cancel");
    
    
    public static void main (String args[]) {
        ActivityUI activity = new ActivityUI();
        activity.dialogBoxLoader();
    }
    
    public void addActivity(){
        dialogBoxLoader();
    }

    
    public void editActivity(){
        dialogBoxLoader();
    }
    
    public void dialogBoxLoader(){
        dbox.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        dbox.setSize(400,270);
        dbox.setLayout(null);
        
        ok.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    if (itemField.getText().isEmpty()) 
                        JOptionPane.showMessageDialog(dbox,"Please answer all fields\n"+" ", "Error", JOptionPane.ERROR_MESSAGE);
                    
                    else if (intCheck(itemField.getText()))
                        JOptionPane.showMessageDialog(dbox,"Items should only consist of integers\n"+" ", "Invalid Input.", JOptionPane.ERROR_MESSAGE);
                    else {
                        JOptionPane.showMessageDialog(dbox,"<Name of activity> has been succesfully added.\n"+" ");
                        close();
                    }
                }
        });
        cancel.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    close();
                }
        });
        
        actLabel.setSize(58, 16);
        itemLabel.setSize(58, 16);
        actLabel.setLocation(80, 70);
        itemLabel.setLocation(90, 110);
        actLabel.setVisible(true);
        itemLabel.setVisible(true);
        
        actList.setSize(150, 26);
        itemField.setSize(150, 26);
        actList.setLocation(145, 70);
        itemField.setLocation(145, 110);
        actList.setVisible(true);
        itemField.setVisible(true);
        
        
        ok.setSize(80, 25);
        cancel.setSize(80, 25);
        ok.setLocation(100, 160);
        cancel.setLocation(190, 160);
        ok.setVisible(true);
        cancel.setVisible(true);
        
        dbox.add(ok);
        dbox.add(cancel);
        dbox.add(actLabel);
        dbox.add(itemLabel);
        dbox.add(actList);
        dbox.add(itemField);
        dbox.setVisible(true);
    }
    
    public void close(){
        dbox.dispose();
    }
    
    public boolean intCheck(String what) {
        boolean tf = false;
        for (int i = 0; what.length()>i; i++) {
            for (char j='A'; 'z'>j; j++) {
                if (what.charAt(i)==j)
                tf = true;
            }
        }
        return tf;
    }
}
